thin.imports('/public/configure/conf.advisory.js');
thin.imports('/public/plug/laytpl/laytpl.js');
thin.imports('/public/plug/LoadEffect/LoadEffect.js');

// markdown编辑器资源
thin.imports('/public/plug/editormd/lib/marked.min.js');
thin.imports('/public/plug/editormd/lib/underscore.min.js');
thin.imports('/public/plug/editormd/lib/raphael.min.js');
thin.imports('/public/plug/editormd/lib/prettify.min.js');
thin.imports('/public/plug/editormd/lib/sequence-diagram.min.js');
thin.imports('/public/plug/editormd/lib/flowchart.min.js');
thin.imports('/public/plug/editormd/lib/jquery.flowchart.min.js');
thin.imports('/public/plug/editormd/src/editormd.js');

thin.use(function() {
	// 頁面加載完畢
	thin.effect();

	if(thin.data['data-id'] > 0) {
		// 讀取資訊詳情
		layer.load(0, {
			shade: [0.08, '#000']
		});
		__getdata_imdetail['id'] = thin.data['data-id'];
		factory.request('_information_get');
	}

	// 先獲取html
	volistTPL = $('#imvolist-template').html();

	// 獲取資訊列表
	factory.request('_information_volist');
});

var volistTPL,
	__getdata_imdetail = {};

// 獲取資訊詳情回調
function __complete_imdetail(res) {
	layer.closeAll('loading');
	if(res.status == 200) {
		bindimdetail(res.data);
	} else {
		// nothing
	}
}

// 綁定數據
function bindimdetail(data) {
	$('#bind-de-cover').attr('src', data.cover);
	$('#bind-de-title').html(data.title);
	$('#bind-de-reading').html(data.reading);
	$('#bind-de-create_time').html(tool.formatDate('yy-mm-dd', data.create_time));
	//$('#bind-de-content').html(data.content);
	var val = data.content;
	val = val.replace(/&lt;/gi, '<');
	//$('#content').html('');
	testEditormdView = editormd.markdownToHTML("bind-de-content", {
		markdown: val,
		htmlDecode: "style,script,iframe", // you can filter tags decode
		tocm: true, // Using [TOCM]
		emoji: true,
		taskList: true,
		tex: true, // 默认不解析
		flowChart: true, // 默认不解析
		sequenceDiagram: true, // 默认不解析
	});
}

// 獲取資訊列表回調
function __complete_imvolist(res) {
	layer.closeAll('loading');
	if(res.status == 200) {
		if(res.data.list.length > 0) {
			var tpl = laytpl(volistTPL);
			$('#imvolist-view').html(tpl.render(res.data.list)).show();
		} else {
			$('#imvolist-view').parent().addClass('nothing-bg');
		}
	} else {
		layer.msg(res.error, {
			icon: 2,
			time: 800
		});
	}
}